<?php
require('config.php');

        $user_id=$_REQUEST['user_id'];
        //$user_id=9;
		$sql="select * from `".$oto."_orders`,`".$oto."_order_goods` where ".$oto."_orders.userId='".$user_id."' and `orderFlag`='1' and ".$oto."_orders.orderId=".$oto."_order_goods.orderId and ".$oto."_orders.orderType!='4' and orderFlag='1' order by ".$oto."_orders.createTime DESC";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$person_info[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(isset($person_info))
		{
			for($i=0;$i<count($person_info);$i++)
			{
				$shopId=$person_info[$i]['shopId'];
				$orderType=$person_info[$i]['orderType'];
				if($orderType==4)
				{
					$sql="select fieldValue from `".$oto."_sys_configs` where fieldName='商城名称'";
					$result=$db->query($sql);
					while($row=$result->fetch_assoc()){
						$cofig1[$i]=$row;//将取得的所有数据赋值给person_info数组
					}
					$sql="select fieldValue from `".$oto."_sys_configs` where fieldName='商城Logo'";
					$result=$db->query($sql);
					while($row=$result->fetch_assoc()){
						$cofig2[$i]=$row;//将取得的所有数据赋值给person_info数组
					}
					$person_info[$i]['shopName']=$cofig1[$i]['fieldValue'];
					$person_info[$i]['shopImg']=$cofig2[$i]['fieldValue'];
				}
				else
				{
					$sql="select shopName,shopImg from `".$oto."_shops` where shopId='$shopId'";
					$result=$db->query($sql);
					while($row=$result->fetch_assoc()){
						$shop_info[$i]=$row;//将取得的所有数据赋值给person_info数组
					}
					if(isset($shop_info[$i]))
					{
						$person_info[$i]['shopName']=$shop_info[$i]['shopName'];
						$person_info[$i]['shopImg']=$shop_info[$i]['shopImg'];
					}
					else
					{
						$person_info[$i]['shopName']='';
						$person_info[$i]['shopImg']='';
					}
				}
				
			}
			$order=$person_info;
			if(isset($order))
			{
				$pan_tiao=0;
				$t=0;
				for($i=0;$i<count($order);$i++)
				{
					if($order[$i]['orderunique']!=$pan_tiao)
					{
						$data[$t]['orderId']=$order[$i]['orderId'];
						$data[$t]['shopName']=$order[$i]['shopName'];
						$data[$t]['shopImg']=$order[$i]['shopImg'];
						$data[$t]['shopId']=$order[$i]['shopId'];
						$data[$t]['needPay']=$order[$i]['needPay'];
						$data[$t]['orderStatus']=$order[$i]['orderStatus'];
						$data[$t]['deliverMoney']=$order[$i]['deliverMoney'];
						$data[$t]['createTime']=$order[$i]['createTime'];
						$t2=0;
						for($j=0;$j<count($order);$j++)
						{
							if($order[$i]['orderunique']==$order[$j]['orderunique'])
							{
								$data[$t]['list'][$t2]=$order[$j];
								$t2++;
							}
						}
						if($t2==0) $data[$t]['list']=[];
						$t++;
						$pan_tiao=$order[$i]['orderunique'];
					}
				}
				echo json_encode($data);
			}
			else echo '[]';
		}
		else echo '[]';
		//echo json_encode($person_info);
?>